function F = nashN(nu,mc,a,b,par_beta)

%
% This function finds the nash equil. for the case where there are N firms
% (find prices sequentially)
%

global tol1 flg_otpt

% initial guess of prices (price of outside good equal to zero)
    nmb = length(nu);
    old_prc = zeros(nmb,1);
    new_prc = zeros(nmb,1);
    old_prc=mc;    
    
% Sequential loop over firm prices, starting with newest vintage
% Finding best-price response for vintage (i), holding all other prices
% fixed.  Then moving onto (i+1), etc.  Stop when at a nash equil.
cnt = 1;
diff_prc=100;
while (diff_prc>tol1)
    tmp=zeros(size(old_prc));
    for i=nmb:-1:2
        new_prc(i) = firmN(old_prc,nu,mc,a,b,i,par_beta);
        tmp(i) = abs(old_prc(i)-new_prc(i));
        old_prc(i) = new_prc(i);
    end
    
    diff_prc = max(tmp);
%    disp('New prices');
%    disp(new_prc);
    cnt = cnt+1;
    if(cnt>1000)
        diff_prc=0;
        disp('Nash equil. didnt converge');
        disp(new_prc); disp(par_beta);disp([a b 1.0]);
%        disp('pause'); pause
    end
end
disp(['count is:  ' num2str(cnt)]);


% Check Nash equil for high quality firm
if flg_otpt>0
    disp('For highest quality firm');
    prft=zeros(3,1);
    dmd = demand(new_prc,nu,a,b,par_beta);
    prft(2) = (new_prc(nmb)-mc(nmb))*dmd(nmb);

    prc_tmp = new_prc;
    prc_tmp(nmb) = new_prc(nmb)*1.005;
    dmd = demand(prc_tmp,nu,a,b,par_beta);
    prft(3) = (prc_tmp(nmb)-mc(nmb))*dmd(nmb);

    prc_tmp = new_prc;
    prc_tmp(nmb) = new_prc(nmb)*0.995;
    dmd = demand(prc_tmp,nu,a,b,par_beta);
    prft(1) = (prc_tmp(nmb)-mc(nmb))*dmd(nmb);

    disp('Checking Nash Equil with 0.5% price deviations-middle should be highest');
    disp(prft);

    disp('For 2nd-highest quality firm');
    prft=zeros(3,1);
    dmd = demand(new_prc,nu,a,b,par_beta);
    prft(2) = (new_prc(nmb-1)-mc(nmb-1))*dmd(nmb-1);

    prc_tmp = new_prc;
    prc_tmp(nmb-1) = new_prc(nmb-1)*1.005;
    dmd = demand(prc_tmp,nu,a,b,par_beta);
    prft(3) = (prc_tmp(nmb-1)-mc(nmb-1))*dmd(nmb-1);

    prc_tmp = new_prc;
    prc_tmp(nmb-1) = new_prc(nmb-1)*0.995;
    dmd = demand(prc_tmp,nu,a,b,par_beta);
    prft(1) = (prc_tmp(nmb-1)-mc(nmb-1))*dmd(nmb-1);

    disp('Checking Nash Equil with 0.5% price deviations-middle should be highest');
    disp(prft);

    disp('For 3rd-highest quality firm');
    prft=zeros(3,1);
    dmd = demand(new_prc,nu,a,b,par_beta);
    prft(2) = (new_prc(nmb-2)-mc(nmb-2))*dmd(nmb-2);

    prc_tmp = new_prc;
    prc_tmp(nmb-2) = new_prc(nmb-2)*1.005;
    dmd = demand(prc_tmp,nu,a,b,par_beta);
    prft(3) = (prc_tmp(nmb-2)-mc(nmb-2))*dmd(nmb-2);

    prc_tmp = new_prc;
    prc_tmp(nmb-2) = new_prc(nmb-2)*0.995;
    dmd = demand(prc_tmp,nu,a,b,par_beta);
    prft(1) = (prc_tmp(nmb-2)-mc(nmb-2))*dmd(nmb-2);

    disp('Checking Nash Equil with 0.5% price deviations-middle should be highest');
    disp(prft);

    disp('For 4th-highest quality firm');
    prft=zeros(3,1);
    dmd = demand(new_prc,nu,a,b,par_beta);
    prft(2) = (new_prc(nmb-3)-mc(nmb-3))*dmd(nmb-3);

    prc_tmp = new_prc;
    prc_tmp(nmb-3) = new_prc(nmb-3)*1.005;
    dmd = demand(prc_tmp,nu,a,b,par_beta);
    prft(3) = (prc_tmp(nmb-3)-mc(nmb-3))*dmd(nmb-3);

    prc_tmp = new_prc;
    prc_tmp(nmb-3) = new_prc(nmb-3)*0.995;
    dmd = demand(prc_tmp,nu,a,b,par_beta);
    prft(1) = (prc_tmp(nmb-3)-mc(nmb-3))*dmd(nmb-3);

    disp('Checking Nash Equil with 0.5% price deviations-middle should be highest');
    disp(prft);

end


F = new_prc;
